const {
  DataTypes
} = require('sequelize');

const seq = require('../db/seq');
const Goods = require('../model/goods');

const goods = Goods(seq);

module.exports = sequelize => {
  const attributes = {
    indent_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: null,
      primaryKey: true,
      autoIncrement: true,
      comment: "订单ID",
      field: "indent_id"
    },
    user_id: {
      type: DataTypes.STRING(255),
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "用户ID",
      field: "user_id",
      references: {
        key: "user_id",
        model: "user_model"
      }
    },
    goods_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "商品ID",
      field: "goods_id",
      references: {
        key: "goods_id",
        model: "goods_model"
      }
    },
    goods_price: {
      type: DataTypes.DECIMAL,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "商品价格",
      field: "goods_price"
    },
    goods_number: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "商品购买数量",
      field: "goods_number"
    },
    indent_total: {
      type: DataTypes.DECIMAL,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "订单总价",
      field: "indent_total"
    },
    create_time: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "订单创建时间",
      field: "create_time"
    },
    shipping_name: {
      type: DataTypes.STRING(30),
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "物流名称",
      field: "shipping_name"
    },
    shipping_code: {
      type: DataTypes.STRING(30),
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "物流单号",
      field: "shipping_code"
    },
    indent_status: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "订单状态：1、未付款，2、已付款，3、未发货，4、已发货，5、交易成功，6、交易关闭",
      field: "indent_status"
    },
    indent_remarks: {
      type: DataTypes.STRING(255),
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "订单备注",
      field: "indent_remarks"
    }
  };
  const options = {
    tableName: "indent",
    comment: "",
    indexes: [{
      name: "user_id",
      unique: false,
      type: "BTREE",
      fields: ["user_id"]
    }, {
      name: "goods_id",
      unique: false,
      type: "BTREE",
      fields: ["goods_id"]
    }]
  };
  const IndentModel = sequelize.define("indent_model", attributes, options);
  IndentModel.belongsTo(goods, {
    foreignKey: 'goods_id',
    as: 'goods_info',
  })
  return IndentModel;
};